/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.taglib.head.js;

import javax.servlet.jsp.tagext.TagSupport;

import com.genia.toolbox.web.constant.SpringBeanNames;

/**
 * tag to register a new js script.
 */
@SuppressWarnings("serial")
public class SpringJsAddScript
    extends TagSupport
{

  /**
   * whether the client can cache the file.
   */
  private boolean cache = true;

  /**
   * the {@link JsScriptContainer} to use.
   */
  private JsScriptContainer jsScriptContainer;

  /**
   * the priority of the js link.
   */
  private int priority = 0;

  /**
   * the script link.
   */
  private String src = null;

  /**
   * spring name where to get the UrlManager.
   */
  private String urlManagerName = SpringBeanNames.DEFAULT_URL_MANAGER_NAME;



  /**
   * Processing of the start tag.
   * 
   * @return SKIP_BODY
   */
  @Override
  public int doStartTag()
  {
    getJsScriptContainer().addScript(getSrc(), getUrlManagerName(), isCache(), getPriority());
    return SKIP_BODY;
  }



  /**
   * getter for the jsScriptContainer property.
   * 
   * @return the jsScriptContainer
   */
  public JsScriptContainer getJsScriptContainer()
  {
    return jsScriptContainer;
  }



  /**
   * getter for the priority property.
   * 
   * @return the priority
   */
  public int getPriority()
  {
    return priority;
  }



  /**
   * getter for the src property.
   * 
   * @return the src
   */
  public String getSrc()
  {
    return src;
  }



  /**
   * getter for the urlManagerName property.
   * 
   * @return the urlManagerName
   */
  public String getUrlManagerName()
  {
    return urlManagerName;
  }



  /**
   * getter for the cache property.
   * 
   * @return the cache
   */
  public boolean isCache()
  {
    return cache;
  }



  /**
   * Release state.
   */
  @Override
  public void release()
  {
    super.release();
    urlManagerName = SpringBeanNames.DEFAULT_URL_MANAGER_NAME;
    src = null;
    cache = true;
    priority = 0;
  }



  /**
   * setter for the cache property.
   * 
   * @param cache
   *          the cache to set
   */
  public void setCache(boolean cache)
  {
    this.cache = cache;
  }



  /**
   * setter for the jsScriptContainer property.
   * 
   * @param jsScriptContainer
   *          the jsScriptContainer to set
   */
  public void setJsScriptContainer(JsScriptContainer jsScriptContainer)
  {
    this.jsScriptContainer = jsScriptContainer;
  }



  /**
   * setter for the priority property.
   * 
   * @param priority
   *          the priority to set
   */
  public void setPriority(int priority)
  {
    this.priority = priority;
  }



  /**
   * setter for the src property.
   * 
   * @param src
   *          the src to set
   */
  public void setSrc(String src)
  {
    this.src = src;
  }



  /**
   * setter for the urlManagerName property.
   * 
   * @param urlManagerName
   *          the urlManagerName to set
   */
  public void setUrlManagerName(final String urlManagerName)
  {
    this.urlManagerName = urlManagerName;
  }

}
